package com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.minordeath.riskstrategy;

import com.bmps.springcloud.insuredmicroservice.constant.accept.StrategyConstant;
import com.bmps.springcloud.insuredmicroservice.model.accept.LcPolModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.ProductModel;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

/**
 * description:
 * LBT026
 *
 * @author jackdaw
 * @date 2020-01-07 18:09
 */
@Component
public class Lbt026RiskStrategy implements RiskStrategy {
    @Override
    public BigDecimal getAmount(LcPolModel lcPolModel, List<LcPolModel> lcPolModels, boolean current) {
        BigDecimal prem = lcPolModel.getPrem();
        for (LcPolModel model : lcPolModels) {
            if (StringUtils.equals(model.getRiskCode(), StrategyConstant.AAT064)) {
                if (current || StringUtils.equals(lcPolModel.getPrtNo(), model.getPrtNo())) {
                    prem = prem.add(model.getPrem());
                }

            }
        }
        if (lcPolModel.getPayIntv() == 1) {
            prem = prem.multiply(BigDecimal.valueOf(12));
        }

        if (18 - lcPolModel.getInsuredAppAge() < lcPolModel.getPayYears()) {
            return lcPolModel.getAmnt().multiply(BigDecimal.valueOf(3)).add(prem.multiply(BigDecimal.valueOf(0.6 * (18 - lcPolModel.getInsuredAppAge()))));
        } else {
            return lcPolModel.getAmnt().multiply(BigDecimal.valueOf(3)).add(prem.multiply(BigDecimal.valueOf(0.6 * lcPolModel.getPayYears())));
        }
    }
}
